/*
https://leetcode.cn/problems/koko-eating-bananas/submissions/570834633/
爱吃香蕉的珂珂
二分查找
*/
class Solution {
public:
    bool check(vector<int>& piles, int h, int& k) {
        for (int i = 0; i < piles.size(); ++i) {
            h -= (piles[i] + k - 1) / k;
            if (h < 0) {
                return false;
            }
        }
        return true;
    }

    int minEatingSpeed(vector<int>& piles, int h) {
        int left = 1, right = 1000000000;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (check(piles, h, mid)) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return left;
    }
};